#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ams = nullptr;

    setWindowTitle("自动环路贪吃蛇 OvO ");
}

MainWindow::~MainWindow()
{
    delete ui;
}

//自动贪吃蛇
void MainWindow::on_autoModeButton_clicked()
{
    this->hide();
    ams = new AMSnake;
    QObject::connect(ams, SIGNAL(showMainWindow()), this, SLOT(receiveShowMainWindow()));
    if(!ams->play())
        receiveShowMainWindow();
}

//接受showMainWindow信号
void MainWindow::receiveShowMainWindow()
{
    if(ams != nullptr) {delete ams; ams = nullptr;}
    this->show();
}
